;; android-java.srt --- Templates for Android Java files
;;
;; Copyright (C) 2011 Eric M. Ludlam
;;
;; Author: Eric M. Ludlam <eric@siege-engine.com>
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.

;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

set mode "java-mode"
set escape_start "$"
set escape_end "$"

set framework "android"

context declaration

template activity :indent :java
"Create a new activity class."
----
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuInflater;
import android.view.Menu;
import android.view.View;
import android.content.Intent;

public class $FILENAME_AS_CLASS$ extends Activity
{
    /** Called when the activity is first created. */
    @Override
	public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.$?LAYOUT$);
    }

    @Override
	protected void onStop()
    {
	super.onStop();

    }
----

context function

prompt RES_ID "Resource Id: " read srecode-android-read-resource-id

template addclicklistener :indent
"Add an 'OnClick' listener to a button with some id."
----
// Bind the action for the save button.
findViewById(R.id.$?RES_ID$).setOnClickListener($RES_ID$ClickListener);
----


context classdecl

template addclicklistenerimpl :indent :java
"Create the implementation of an 'OnClick' listener for some resource ID"
----
View.OnClickListener $?RES_ID$ClickListener = new View.OnClickListener() {
    public void onClick(View v) {
	    Intent myIntent = new Intent();
	    myIntent.setClassName("$CURRENT_PACKAGE$", "$CURRENT_PACKAGE$.$?ACTIVITY$");
	    startActivity(myIntent);
    }
};
----

template onCreateOptionsMenu :indent :java
----
    @Override
	public boolean onCreateOptionsMenu(Menu menu) 
    {
	MenuInflater inflater = getMenuInflater();
	inflater.inflate(R.menu.$?RES_ID$, menu);
	return true;
    }
----


;; end